const connections = require("../app/database")

class UserService {
  async create({name,password}){
    //将user存储到数据库中
    const statement = `INSERT INTO user (name,password) VALUES (?,?)`

    const result = await connections.promise().execute(statement,[name,password])

    return result
  }

  async getUserByName(name){
    const statement = `SELECT * FROM user where name = ?`;
    const result = await connections.promise().execute(statement,[name])
    return result[0]
  }

  async updateAvatarUrlById(userId,avatarUrl){
    const statement = `UPDATE user SET avatar_url = ? WHERE id = ?`
    const [result] = await connections.promise().execute(statement,[avatarUrl,userId])
    return result
  }

}

module.exports = new UserService()